public class Test {
    public static void main(String[] args) {
        int[] arr = {11,22,33,34,45,56,78,67,89,10};
        int ret = binarySearch(arr,99);
        System.out.println(ret);
    }

    //默认数组升序
    public static int binarySearch(int[] arr,int key) {
        int left = 0;
        int right = arr.length-1;
        while(left <= right) {
            int mid = (left + right) / 2;
            if(arr[mid] == key) {
                return arr[mid];
            } else if(arr[mid] < key) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        return -1;
    }
}
